package com.WISSC.controller;

import com.WISSC.bean.User;
import com.WISSC.bean.WebPage;
import com.WISSC.bean.layuiBean.ResultPage;
import com.WISSC.bean.layuiBean.VoPage;
import com.WISSC.service.WebPageService;
import com.WISSC.util.Respons.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.net.PortUnreachableException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/webPage")
@Api(value = "网页样式设置 controller", tags = "网站样式")
public class WebPageController {

    @Autowired
    WebPageService webPageService;
    //进入页面版式页面
    @RequestMapping("/webPage.html")
    public String webPage(){
        return "/webPage/webPage";
    }
    //分页查询所有版式
    @RequestMapping(value = "/selectMyPage",method = RequestMethod.GET)
    @ResponseBody
    public ResultPage<WebPage> selectMyPage(VoPage voPage){
        return webPageService.selectMyPage(voPage);
    }
    //跳转编辑页面
    @RequestMapping(value = "/edit.html")
    @ApiOperation(value = "跳转页面")
    public String  edit(Model model , String id){
        model.addAttribute("id",id);
        return "webPage/webPage_edit";

    }
    //跳转图片编辑页面
    @RequestMapping(value = "/image.html")
    @ApiOperation(value = "跳转页面")
    public String  image(Model model , String id){
        model.addAttribute("id",id);
        return "webPage/webPage_image";

    }

    @RequestMapping("/webPage_edit")
    @ResponseBody
    public Map webPage_edit(@RequestBody WebPage webPage){
        System.out.println(webPage);
        if(webPageService.updateById(webPage)){
            return  ResponseUtil.getSuccessMap();
        }
        return ResponseUtil.getExceptionMap();
    }

    @RequestMapping("/sss")
    @ResponseBody
    public void setPage(Model model){

       model.addAttribute("list",webPageService.selectAll());
    }



}
